﻿using Autofac;
using DBContext;
using EV.EventBus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZoneLine.Common;
using ZoneLine.Models.PackageModel;
using ZoneLine.ViewModels;

namespace ZoneLine.Views
{
    /// <summary>
    /// LableCompensate.xaml 的交互逻辑
    /// </summary>
    public partial class LableCompensate : UserControl
    {
        public LableCompensate()
        {
            InitializeComponent();
            MessageCenter.Subscribe(nameof(LableCompenstateViewModel), Guid.NewGuid().ToString(), (s) =>
            {
                if (s.Source.Payload is string ss)
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        var viewModel = this.DataContext as LableCompenstateViewModel;
                        if (viewModel != null)
                        {
                            viewModel.ProductNo = ss;
                        }
                    });
                }
                return Task.CompletedTask;
            });
        }

        private void MyDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var dataGrid = sender as DataGrid;
            var selectedItem = dataGrid.SelectedItem as AbsPrintResult;

            if (selectedItem != null)
            {
                var viewModel = this.DataContext as LableCompenstateViewModel;
                if (viewModel != null)
                {
                    viewModel.LabelCode = selectedItem.Code;
                }
            }
        }
    }
}